#include <dbg.h>

#include <cassert>

using namespace std;

class Solution {
public:
    int appendCharacters(string s, string t) {
        int indexT = 0;
        int tSize = t.size();
        for (char c : s) {
            if (c == t[indexT]) {
                ++indexT;
                if (indexT == tSize) {
                    return 0;
                }
            }
        }
        return tSize - indexT;
    }
};

int main() {
    Solution s;

    string s1 = "coaching";
    string s2 = "abcde";
    string s3 = "z";

    string t1 = "coding";
    string t2 = "a";
    string t3 = "abcde";

    assert(s.appendCharacters(s1, t1) == 4);
    assert(s.appendCharacters(s2, t2) == 0);
    assert(s.appendCharacters(s3, t3) == 5);

    return 0;
}